#include "bytelib.h"
#include <stdint.h>

void Wuint16(void *address, uint16_t data)
{
    uint8_t *addr = (uint8_t *)address;
    addr[0] = (uint8_t)data;
    addr[1] = (uint8_t)(data >> 8);
}

uint16_t Ruint16(const void *address)
{
    const uint8_t *addr = (const uint8_t *)address;
    uint16_t lowByte = addr[0];
    uint16_t highByte = addr[1];
    return (highByte << 8) | lowByte;
}

void Wuint32(void *address, uint32_t data)
{
    uint8_t *addr = (uint8_t *)address;
    addr[0] = (uint8_t)data;
    addr[1] = (uint8_t)(data >> 8);
    addr[2] = (uint8_t)(data >> 16);
    addr[3] = (uint8_t)(data >> 24);
}

uint32_t Ruint32(const void *address)
{
    const uint8_t *addr = (const uint8_t *)address;
    uint32_t byte1 = addr[0];
    uint32_t byte2 = addr[1];
    uint32_t byte3 = addr[2];
    uint32_t byte4 = addr[3];
    return (byte4 << 24) | (byte3 << 16) | (byte2 << 8) | byte1;
}
